package com.rujian.passwordmanager.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.rujian.passwordmanager.R;
import com.rujian.passwordmanager.bean.PasswordBean;

import java.util.List;

public class PwdListAdapter extends BaseAdapter {
    private Context context = null;
    private List<PasswordBean> passwordBeans = null;

    public PwdListAdapter(Context context,List<PasswordBean> l1) {
        this.context = context;
        this.passwordBeans = l1;
    }

    @Override
    public int getCount() {
        return passwordBeans.size();
    }

    @Override
    public Object getItem(int position) {
        return passwordBeans.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        View view;
        final ViewHolder viewHolder;
        if(convertView != null){
            view = convertView;
            viewHolder = (ViewHolder)view.getTag();
        }else{
            viewHolder = new ViewHolder();
            view = View.inflate(context,R.layout.item_pwd,null);
            viewHolder.name = (TextView)view.findViewById(R.id.tv_account);
            view.setTag(viewHolder);
        }
        PasswordBean passwordBean = passwordBeans.get(position);
        viewHolder.name.setText(passwordBean.mg_nicname);

        return view;
    }

    static class ViewHolder{
        TextView name;
    }

}
